from typing import Any, List
import logging
log = logging.getLogger(__name__)


class BasePlugin(object):
    """
    Abstract base class for hooks, hooks are meant as an interface to
    interact with external systems. MySqlHook, HiveHook, PigHook return
    object that can handle the connection and interaction to specific
    instances of these systems, and expose consistent methods to interact
    with them.
    """

    @classmethod
    def get_connections(cls, conn_id: str) -> List["Connection"]:

        return [cls.get_connection(conn_id)]

    @classmethod
    def get_connection(cls, conn_id: str) -> "Connection":
        """
        Get connection, given connection id.

        :param conn_id: connection id
        :return: connection
        """
        from db_exporter.core.connection import Connection

        conn = Connection.get_connection_from_id(conn_id)
        log.info("Using connection ID '%s' for task execution.", conn.conn_id)
        return conn

    @classmethod
    def get_hook(cls, conn_id: str) -> "BasePlugin":
        """
        Returns default plugin for this connection id.

        """
        connection = cls.get_connection(conn_id)
        return connection.get_hook()

    def get_conn(self) -> Any:
        """Returns connection for the hook."""
        raise NotImplementedError()
